<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="css/public.css" rel="stylesheet">
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/list.css" rel="stylesheet">
    <title>列表页</title>
</head>
<body>


    <!--以上在后台设计的时候放到一个页面中，让别的页面去引用它-->

 
    <div class="row">
        <div class="col-md-9">
            <div class="panel panel-green">
                
         <c:forEach items="${pb.beanList }" var="seed" >
                <div class="panel panel-body">
                    <div class="list-product">
                        <div class="list-left col-md-6">
                            <a href="<c:url value='/SeedServlet?method=load&sid=${seed.sid }'/>"><img src="upfile/${seed.image }"/></a>
                            <ul>
                               <li>${seed.sname }</li>
		    			       <li>零售价格：${seed.price }元</li>
		    			      <li>品种编号：${seed.sid }</li>
		    			       <li>包装规格：${seed.large }g/袋</li>
                            </ul>
                            <a id="${seed.sid}" class="compare btn btn-primary">对比</a>
                            <a href="<c:url value='SeedServlet?method=commentAdd&sid=${seed.sid }'/>" class="btn btn-primary">评论</a>
                        </div>
                        <div class="list-right col-md-6">
                            <h3>特征特性：</h3>
                            <p>${seed.xiangxi }</p>
                            <a href="<c:url value='/SeedServlet?method=load&sid=${seed.sid }'/>">[详细介绍]</a>
                        </div>
                    </div> 
                </div>
                
                </c:forEach>
            </div>
         
            <nav class="col-md-offset-5">
                <ul class="pagination">
                             第${pb.pc }页/共${pb.tp }页
                     <c:if test="${pb.pc>1 }">
                    <li><a href="<c:url value='/AdminSeedServlet?method=findAll&pc=${pb.pc+1 }'/>">&laquo;</a></li>
                       </c:if>       
                    <li class="active"><a  href="<c:url value='/AdminSeedServlet?method=findAll&pc=1'/>">首页</a></li>
                    <c:if test="${pb.pc>1 }">
                    <li><a href="<c:url value='/AdminSeedServlet?method=findAll&pc=${pb.pc-1 }'/>">上一页</a></li>
                    
                    </c:if>
                    <%-- 计算begin、end --%>
<c:choose>
	<%-- 如果总页数不足10页，那么把所有的页数都显示出来！ --%>
	<c:when test="${pb.tp <= 10 }">
		<c:set var="begin" value="1" />
		<c:set var="end" value="${pb.tp }" />
	</c:when>
	<c:otherwise>
		<%-- 当总页数>10时，通过公式计算出begin和end --%>
		<c:set var="begin" value="${pb.pc-5 }" />
		<c:set var="end" value="${pb.pc+4 }" />	
		<%-- 头溢出 --%>
		<c:if test="${begin < 1 }">
			<c:set var="begin" value="1" />
			<c:set var="end" value="10" />
		</c:if>	
		<%-- 尾溢出 --%>
		<c:if test="${end > pb.tp }">
			<c:set var="begin" value="${pb.tp - 9 }" />
			<c:set var="end" value="${pb.tp }" />
		</c:if>	
	</c:otherwise>
</c:choose>
<%-- 循环遍历页码列表 --%>
<c:forEach var="i" begin="${begin }" end="${end }">
	
	<c:choose>
	<c:when test="${i eq pb.pc }">
	[${i }]
	</c:when>
	<c:otherwise>
	<a href="<c:url value='/AdminSeedServlet?method=findAll&pc=${i }'/>">[${i }]</a>
	</c:otherwise>
	</c:choose>
</c:forEach>
                    <c:if test="${pb.pc<pb.tp }">
                    <li><a href="<c:url value='/AdminSeedServlet?method=findAll&pc=${pb.pc+1 }'/>">下一页</a></li>
                     </c:if>
                    <li><a href="<c:url value='/AdminSeedServlet?method=findAll&pc=${pb.tp}'/>">尾页</a></li>
                     <c:if test="${pb.pc<pb.tp }">
                    <li><a href="<c:url value='/AdminSeedServlet?method=findAll&pc=${pb.pc+1 }'/>">&raquo;</a></li>
                    </c:if>
                </ul>
            </nav>
           
        </div>
         
       




    

<div class="tip">
	
</div>
</body>
<script src="js/jquery.min.js"></script>

</html>